home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 142 / Gekkan Dennou Club - 2000.3 Vol. 142 (Japan).7z / Gekkan Dennou Club - 2000.3 Vol. 142 (Japan) (Track 1).bin / tools / s_tool / scsicmd.c < prev    next >
Text File  |  1999-06-11  |  10KB  |  362 lines

  1. #include    "JX250.H"
  2. #include    <sys\iocs.h>
  3. #include    <sys\scsi.h>
  4. #include    <stdio.h>
  5. #include    <stdlib.h>
  6.  
  7. int    request_disp( int );
  8. int _scsi_cmd( int, int, unsigned char *, int, unsigned char * );
  9. int _scsi_cmd_sm();
  10.  
  11. /***************************************
  12.     JX250 自動検索
  13.     si = 検索始めの ID
  14. [out]    ID    ; あった
  15.     ID+0x8000 ; あったが、今は使えない?!
  16.     ID+0xC000 ; あったが、今はリザーブされている
  17.     -1 : なかった
  18. ****************************************/
  19. int    AutoSreachJX(si,gg)
  20. int    si,gg;
  21. {
  22. int    i,j,m,n,id,l,oid,d,jx;
  23. UNchar    buf[128];
  24. l=(TWOSCHK()==-2)?15:7;
  25. oid=-1;
  26. for(d=-1;d<=l;d++){
  27.     if ( d<0 )
  28.         id=si;
  29.     else    id=d;
  30.     if ( id<0 )
  31.         continue;
  32.     //---- inquiry チェック
  33.     BUSYS( i=_scsi_inquiry(36,id,buf) );
  34.     if ( i<0 )
  35.         continue;
  36.     if ( i!=0 ){
  37.         //printf("inquiryでエラー(%d)\n",i);
  38.         if ( i==2 ) request_disp2(id);
  39.         continue;
  40.     }
  41.     if ( buf[0]!=0x06 )
  42.         continue;
  43.     if ( strncmp(&buf[8],"SHARP",5)!=0 )
  44.         continue;
  45.     jx=999;
  46.     if ( strncmp(&buf[16],"JX270",5)==0 )
  47.         jx=_JX270_;
  48.     if ( strncmp(&buf[16],"JX250",5)==0 )
  49.         jx=_JX250_;
  50.     if ( strncmp(&buf[16],"JX350",5)==0 )
  51.         jx=_JX350_;
  52.     if ( strncmp(&buf[16],"JX330",5)==0 )
  53.         jx=_JX330_;
  54.     if ( strncmp(&buf[16],"JX325",5)==0 )
  55.         jx=_JX325_;
  56.     if ( strncmp(&buf[16],"JX-325",6)==0 )
  57.         jx=_JX325_;
  58.     if ( jxscanner_>=0 ){
  59.         if ( jxscanner_!=jx )
  60.             jx=999;
  61.     }
  62.     if ( jx==999 )
  63.         continue;
  64.     jxscanner=jx;        // 0;jx250 1;jx350 -1;jx330
  65.     //---- JXスキャナを発見
  66.     //---- dummy 発行
  67.     BUSYS( i=_scsi_request( 22,id,buf) );
  68.     //---- testunit 発行
  69.     BUSYS( i=_scsi_testunit(id) );
  70.     if ( i!=0 ){
  71.         oid=id;
  72.         continue;
  73.     }
  74.     //-ロゴ変更
  75.     JxLogoChain();
  76.     return(id);
  77. }
  78. if ( oid>=0 )
  79.     return(0x8000+id);
  80. if ( gg!=0 ){
  81.     Dialog(    "サポート出来るス",
  82.         "キャナは接続されて",
  83.         "いないようです。",
  84.         1
  85.     );
  86. }
  87. return(-1);
  88. }
  89. /**************************************************
  90.     _scsi_reseveunit(id)
  91. **************************************************/
  92. int    _scsi_reseveunit(id)
  93. int    id;
  94. {
  95. static    UNchar cm[6]={0x16,0,0,0,0,0};
  96. return( _scsi_cmd( id, 6,cm,0,0 ) );
  97. }
  98. /**************************************************
  99.     _scsi_releaseunit(id)
  100. **************************************************/
  101. int    _scsi_releaseunit(id)
  102. int    id;
  103. {
  104. static    UNchar cm[6]={0x17,0,0,0,0,0};
  105. return( _scsi_cmd( id, 6,cm,0,0 ) );
  106. }
  107. /**************************************************
  108.     _scsi_setwindow(id,length,bufadds)
  109. **************************************************/
  110. int    _scsi_setwindow(id,length,bufadds)
  111. int    id,length;
  112. UNchar    *bufadds;
  113. {
  114. static    UNchar cm[10]={0x24,0,0,0, 0,0,  0,0,0, 0};
  115. cm[6]=(length/0x10000)&0xFF;
  116. cm[7]=(length/0x100)  &0xFF;
  117. cm[8]= length         &0xFF;
  118. return( _scsi_cmd( id, 10,cm, (length|DATAOUT),bufadds ) );
  119. }
  120. /**************************************************
  121.     _scsi_getwindow(id,length,bufadds)
  122. **************************************************/
  123. int    _scsi_getwindow(id,length,bufadds)
  124. int    id,length;
  125. UNchar    *bufadds;
  126. {
  127. if ( jxscanner!=_JX270_ ){
  128.     static    UNchar cm[10]={0x25,0,0,0, 0,0,  0,0,0, 0};
  129.     cm[6]=(length/0x10000)&0xFF;
  130.     cm[7]=(length/0x100)  &0xFF;
  131.     cm[8]= length         &0xFF;
  132.     return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
  133. }
  134. // JX270 は getwindow 命令、無い(汗)。
  135. }
  136. /**************************************************
  137.     _scsi_send(id,dtc,dtq,length,bufadds)
  138. **************************************************/
  139. int    _scsi_send(id,dtc,dtq,length,bufadds)
  140. int    id,dtc,dtq,length;
  141. UNchar    *bufadds;
  142. {
  143. static    UNchar cm[10]={0x2A,0,0,0, 0,0,  0,0,0, 0};
  144. cm[2]=dtc;
  145. *(UNshort*)&cm[4]=dtq;
  146. cm[6]=(length/0x10000)&0xFF;
  147. cm[7]=(length/0x100)  &0xFF;
  148. cm[8]= length         &0xFF;
  149. return( _scsi_cmd( id, 10,cm, (length|DATAOUT),bufadds ) );
  150. }
  151. /**************************************************
  152.     _scsi_scan(id)
  153. **************************************************/
  154. int    _scsi_scan(id)
  155. int    id;
  156. {
  157. static    UNchar cm[10]={0x1B,0,0,0, 0,0};
  158. return( _scsi_cmd( id, 6,cm, 0 ,0 ) );
  159. }
  160. /**************************************************
  161.     _scsi_scanread(id,dtc,dtcq,length,bufadds)
  162. **************************************************/
  163. int    _scsi_scanread(id,dtc,dtcq,length,bufadds)
  164. int    id,dtc,dtcq,length;
  165. UNchar    *bufadds;
  166. {
  167. static    UNchar cm[10]={0x28,0,0,0, 0,0,  0,0,0, 0};
  168. cm[2]=dtc;
  169. *(UNshort*)&cm[4]=dtcq;
  170. cm[6]=(length/0x10000)&0xFF;
  171. cm[7]=(length/0x100)  &0xFF;
  172. cm[8]= length         &0xFF;
  173. return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
  174. }
  175. /*++++*/
  176. int    _scsi_scanread27(id,dtc,dtcq,length,bufadds)
  177. int    id,dtc,dtcq,length;
  178. UNchar    *bufadds;
  179. {
  180. static    UNchar cm[10]={0x28,0,0,1, 0,0,  0,0,0, 0};
  181. cm[2]=dtc;
  182. *(UNshort*)&cm[4]=dtcq;
  183. cm[6]=(length/0x10000)&0xFF;
  184. cm[7]=(length/0x100)  &0xFF;
  185. cm[8]= length         &0xFF;
  186. return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
  187. }
  188. /**************************************************
  189.     _scsi_initialize(id):JX250,350 特有のもの
  190. **************************************************/
  191. int    _scsi_initialize(id)
  192. int    id;
  193. {
  194. if ( jxscanner==_JX250_ || jxscanner==_JX350_ ){
  195.     static    UNchar cm[10]={0xFF,0,0,0,0, 0,0,0,0,0};
  196.     return( _scsi_cmd( id,10,cm,0,0 ) );
  197. } elif ( jxscanner==_JX330_ || jxscanner==_JX270_ ){
  198.     static    UNchar cm[6]={0x00,0,0,0,0,0};
  199.     int    i;
  200. //    i=_scsi_msg_reset( id,6,cm);
  201.     request_disp2(id);    //dummy 発行
  202.     request_disp2(id);    //dummy 発行
  203. }
  204. return( 0 );
  205. }
  206. /***************************************************
  207.  
  208. ***************************************************/
  209. asm("
  210.     .globl    _TWOSCHK
  211. _TWOSCHK:
  212.     move.l    #$001E,d1
  213.     moveq    #$f5,d0
  214.     trap    #15
  215.     rts
  216. ");
  217. /************************************************
  218.     REQUEST
  219. ************************************************/
  220. int    request_disp(id)
  221. int    id;
  222. {
  223. static char    *REQUEST_MSG[17] = {
  224.     "No Se(0): 装置には、異常は、なかった\n",
  225.     "Recovered Error (1): 装置自体のリトライ機能によりコマンドが正常に終了した\n",
  226.     "Not Ready (2): 装置自体に異常が発生し、オペレータの介入が必要であることを示"
  227.             "す\n",
  228.     "Medium Error (3): リード/ライト動作時において媒体に起因するエラーが発生し、"
  229.             "リトライでエラーが回復できなかった\n",
  230.     "Hardware Error (4): 装置のハードウェアに障害が発生し、コマンドの実行が正常終"
  231.             "了しなかった\n",
  232.     "Illegal Request(5):イニシエータからのコマンド・データに異常があり、コマンドの"
  233.             "実行ができなかった\n",
  234.     "Unit Attention (6): 装置がリセットされたことを示す。又メディアが入れ換えられた"
  235.             "ことも示す\n",
  236.     "Write Protected (7): ライト・プロテクト状態にあるときにライト動作を含むコマンド"
  237.             "を受け取ったことを示す\n",
  238.     "Blank Check (8): 読みだし中にブランク領域になった。又は、書き込み中にブランク領"
  239.             "域でない領域になった\n",
  240.     "Vendor Unique (9): メーカーごとに自由に使用可\n",
  241.     "Copy Aborted (A): Copy,Compare,Copy & Verifyコマンドがデバイス異常により中止し"
  242.             "た\n",
  243.     "Aborted Command (B): ターゲットがイニシエータからのコマンドをアボートしたこと"
  244.             "を示す\n",
  245.     "Equal (C): Searchコマンドで一致を検出した\n",
  246.     "Volume Overflow (D): データがバッファに残っているのに、デバイスは最終ブロック"
  247.             "に達してしまった\n",
  248.     "Miscompare (E): ソースデータとメディアから読み出したデータが一致しない\n",
  249.     "(F): 将来の拡張用\n",
  250.             "センス・コマンドでエラーが、発生しました。\n"
  251. };
  252. UNchar    buf[256];
  253. int    sense,sensecode,qualifier;
  254. if ( _scsi_request( 22, id, buf ) == 0 )
  255.     sense = (unsigned int)( buf[2] & 0x0f );
  256. else    sense = 16;
  257. sensecode=buf[12];
  258. qualifier=buf[13];
  259. printf("Check Condition!!    Sense Key = %2Xh\n",sense);
  260. printf("          Sense code(ASC) = %2Xh\n",sensecode);
  261. printf("          Qualifier(ASCQ) = %2Xh\n",qualifier);
  262. printf("               Infomation = %02X%02X%02X%02Xh\n",buf[3],buf[4],buf[5],buf[6]);
  263. printf( REQUEST_MSG[sense] );
  264. return( sense*0x10000+sensecode*0x100+qualifier );
  265. }
  266. /*+++++*/
  267. int    request_disp2(id)
  268. int    id;
  269. {
  270. UNchar    buf[256];
  271. int    sense,sensecode,qualifier;
  272. //
  273. if ( _scsi_request( 22, id, buf ) == 0 )
  274.     sense = (unsigned int)( buf[2] & 0x0f );
  275. else    sense = 16;
  276. sensecode=buf[12];
  277. qualifier=buf[13];
  278. return( sense*0x10000+sensecode*0x100+qualifier );
  279. }
  280. /*******************************************************
  281.  
  282.     int scsi_cmd(
  283.         int id
  284.             SCSI-ID
  285.         int len
  286.             CDB の長さ
  287.         unsigned char *buf
  288.             CDB のアドレス
  289.         int rlen
  290.             データ読み込みの場合、バイト数
  291.             データ書き込みの場合、バイト数|0x80000000
  292.             0ならデータ読み込み無し
  293.         unsigned char *buf2
  294.             データアドレス
  295.  
  296. ********************************************************/
  297. int _scsi_cmd( int id, int len, unsigned char *buf, int rlen, unsigned char *buf2 )
  298. {
  299.     int rc;
  300.     register int ID asm("d4");
  301.     /* セレクションフェーズ */
  302.     ID=id;
  303.     rc  = _scsi_select( ID );
  304.     if ( rc!=0 ) return(-1);
  305.     /* コマンドフェース */
  306.     buf[1]=(buf[1]&0x1F)|(ID/0x10000*0x20);
  307.     rc = _scsi_cmdout( len, buf );
  308.     if ( rc!=0 ) return(-1);
  309.     if( rlen != 0 ){
  310.         if ( rlen>0 ){
  311.             /* データインフェーズ */
  312.             rc = _scsi_datain( rlen, buf2 );
  313.             if ( rc==-1 )
  314.                 return(-1);
  315.             if ( rc==-2 ){
  316.                 rc=_scsi_cmd_sm();
  317.                 if ( rc!=0 )
  318.                     return(rc);
  319.                 return(-2);
  320.             }
  321.         } else {
  322.             /* データアウトフェーズ */
  323.             rc = _scsi_dataout( rlen&0x7FFFFFFF, buf2 );
  324.             if ( rc==-1 )
  325.                 return(-1);
  326.             if ( rc==-2 ){
  327.                 rc=_scsi_cmd_sm();
  328.                 if ( rc!=0 )
  329.                     return(rc);
  330.                 return(-2);
  331.             }
  332.         }
  333.     }
  334.     return( _scsi_cmd_sm() );
  335. }
  336. /*++++++++++++++*/
  337. int _scsi_cmd_sm()
  338. {
  339.     unsigned char status,msg;
  340.     int    rc;
  341.     /* ステイタスフェーズ */
  342.     rc = _scsi_stsin( &status );
  343.     if ( rc!=0 ) return(-1);
  344.     /* メッセージフェーズ */
  345.     rc = _scsi_msgin( &msg );
  346.     if ( rc!=0 ) return(-1);
  347.     return( msg*0x10000 + status );
  348. }
  349. /*+++++++++++*/
  350. int _scsi_msg_reset( int id, int len, unsigned char *buf)
  351. {
  352.     int rc;
  353.     unsigned char status,msg;
  354.     /* セレクションフェーズ */
  355.     rc  = _scsi_select_atn( id );
  356.     if ( rc!=0 ) return(-1);
  357.     /* メッセージアウトフェーズ */
  358.     msg=0x0C;
  359.     rc = _scsi_msgout( &msg );
  360.     return(0);
  361. }
  362.